//
//  AXFGuideViewController.m
//  AXFEightGroup
//
//  Created by ooops on 12/22/16.
//  Copyright © 2016 ya. All rights reserved.
//

#import "AXFGuideViewController.h"
#import "AXFDataModel.h"

@interface AXFGuideViewController ()<CAAnimationDelegate>

@property (weak, nonatomic) IBOutlet UIImageView    *advertImageView;
@property (weak, nonatomic) IBOutlet UIButton       *overButton;
@property (nonatomic, strong) NSTimer *timer;
@end

@implementation AXFGuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [_ModelMgr adverts:^(NSArray<AXFDataModel *> * _Nullable models) {
        [_advertImageView sd_setImageWithURL:[models[0].img_name sj_url]];
    }];

    [_overButton addTarget:self
                    action:@selector(actionClickedOverButton)
          forControlEvents:UIControlEventTouchUpInside];

    self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(ttt) userInfo:nil repeats:YES];

    // Do any additional setup after loading the view.1
}

- (void)ttt {
    static NSInteger index = 6;
    index --;
    [self.overButton setTitle:[NSString stringWithFormat:@"跳过(%zd)", index] forState:UIControlStateNormal];
    if (index == 0) {
        [self actionClickedOverButton];
    }
}

- (void)actionClickedOverButton {
    [self.timer invalidate];

    CABasicAnimation *anima1 = [CABasicAnimation animationWithKeyPath:@"opacity"];
    anima1.fromValue = [NSNumber numberWithFloat:1.0];
    anima1.toValue   = [NSNumber numberWithFloat:0.2];
    anima1.duration  = 0.5;
    [self.view.layer addAnimation:anima1 forKey:@"opacityAnimation"];

    CABasicAnimation *anima2 = [CABasicAnimation animationWithKeyPath:@"transform.scale.x"];
    anima2.toValue   = [NSNumber numberWithFloat:2.0];
    anima2.duration  = 0.5;
    [self.view.layer addAnimation:anima2 forKey:@"scaleAnimation"];

    anima2.delegate = self;
}



- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
    [self.view removeFromSuperview];
}


@end
